#include "cocos2d.h"
#include "CCEGLView.h"
#include "AppDelegate.h"
#include "DungeonScene.h"
#include "TalkScene.h"
#include "GameMainScene.h"
#include "GameState.h"
#include "SimpleAudioEngine.h"
#include "StringManager.h"
#include "ScreenSizeManager.h"

using namespace CocosDenshion;

USING_NS_CC;

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate()
{
	//StringManager::getInstance().RemoveAll();
    SimpleAudioEngine::end();
}

bool AppDelegate::applicationDidFinishLaunching()
{
	// initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

	ScreenSizeManager::setupFixedScreenSize(false);
	ScreenSizeManager::initScreenSize(480, 320);

    // turn on display FPS
    pDirector->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

	//Init values
	Dungeon::left_time = 8 * 60;
	Dungeon::floor = 1;
	Dungeon::SetParty(0, 1, 3, 2);

    // create a scene. it's an autorelease object
    //CCScene *pScene = Dungeon::scene();
	CCScene *pScene = Talk::scene();
	//CCScene *pScene = GameMain::scene();

    // run
    pDirector->runWithScene(pScene);
    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->stopAnimation();

    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->startAnimation();

    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
